package com.breaker.kata.leetcode;

public class MergeOrderedArray {

    public void merge(int[] nums1, int m, int[] nums2, int n) {
        int p = m - 1;
        int q = n - 1;
        int tail = m + n - 1;
        int current;
        while (p >= 0 || q >= 0) {
            if (p == -1) {
                current = nums2[q--];
            } else if (q == -1) {
                current = nums1[p--];
            } else if (nums1[p] > nums2[q]) {
                current = nums1[p--];
            } else {
                current = nums2[q--];
            }
            nums1[tail--] = current;
        }
    }
}
